package 死锁;

/**
 * 一个线程先获取B锁 然后休眠（防止立刻获取到了A锁），等待后去A锁
 * 然后另一个线程获取了A锁，然后等待获取B锁
 *
 * @author zhoujie
 * @Title:
 * @date 2019年3月21日 下午3:35:06
 */
public class Test {

    public static void main(String[] args) {
        new Thread(new Runnable() {

            @Override
            public void run() {
                synchronized (B.class) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    synchronized (A.class) {

                    }
                }
            }
        }).start();
        new Thread(new Runnable() {

            @Override
            public void run() {
                synchronized (A.class) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                    synchronized (B.class) {

                    }
                }

            }
        }).start();
    }

}

class A {

}

class B {

}
